package com.hh.workflow.action;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import org.activiti.engine.task.Attachment;
import org.springframework.beans.factory.annotation.Autowired;

import com.hh.baseframework.util.base.BaseAction;
import com.hh.usersystem.bean.usersystem.HhXtYh;
import com.hh.usersystem.service.impl.LoginUserUtilService;
import com.hh.workflow.service.impl.FileService;

@SuppressWarnings("serial")
public class ActionFile extends BaseAction {
	private byte[] bytes = null;
	private String name;
	private File attachment;
	private String attachmentFileName;
	private String filePath;
	private String dataListString;
	private String taskId;
	private String piid;
	private String type;
	private String id;
	@Autowired
	private FileService fileService;
	@Autowired
	private LoginUserUtilService loginUserUtilService;

	@SuppressWarnings("unchecked")
	public void save() {
		response.setContentType("text/html");
		Attachment attachment2 = fileService.save(type, name, filePath,
				attachment, attachmentFileName, taskId, piid);
		Map<String, String> returnMap = new HashMap<String, String>();
		returnMap.put("path", attachment2.getUrl());
		returnMap.put("attachmentFileName", attachmentFileName);
		returnMap.put("name", name);
		returnMap.put("type", type);
		returnMap.put("id", attachment2.getId());
		HhXtYh user = loginUserUtilService.findLoginUser();
		returnMap.put("userName", user.getText());
		returnMap.put("userId", user.getId());
		returnMap.put("taskId", attachment2.getTaskId());
		this.getResultMap().putAll(returnMap);
		this.returnResult();
	}

	public void queryAttachmentPiid() {
		this.returnResult(fileService.queryAttachmentPiid(piid));
	}
	
	public void queryAttachmentTaskId() {
		this.returnResult(fileService.queryAttachmentTaskId(taskId));
	}

	public void delete() {
		fileService.delete(id);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public File getAttachment() {
		return attachment;
	}

	public void setAttachment(File attachment) {
		this.attachment = attachment;
	}

	public String getAttachmentFileName() {
		return attachmentFileName;
	}

	public void setAttachmentFileName(String attachmentFileName) {
		this.attachmentFileName = attachmentFileName;
	}

	public String getFilePath() {
		return filePath;
	}

	public void setFilePath(String filePath) {
		this.filePath = filePath;
	}

	public byte[] getBytes() {
		return bytes;
	}

	public void setBytes(byte[] bytes) {
		this.bytes = bytes;
	}

	public String getDataListString() {
		return dataListString;
	}

	public void setDataListString(String dataListString) {
		this.dataListString = dataListString;
	}

	public String getTaskId() {
		return taskId;
	}

	public void setTaskId(String taskId) {
		this.taskId = taskId;
	}

	public String getPiid() {
		return piid;
	}

	public void setPiid(String piid) {
		this.piid = piid;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

}
